package com.qf.service.impl;

import com.qf.entity.Admin;
import com.qf.entity.User;
import com.qf.mapper.AdminMapper;
import com.qf.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ProjectName: Dessert-Shop
 * @Package: com.qf.service.impl
 * @ClassName: AdminServiceImpl
 * @Author: 29284
 * @Description:
 * @Date: 2020/7/27 20:19
 * @Version: 1.0
 */
@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;

    @Override
    public Admin login(String admin_name, String admin_pwd) {
        if (admin_name != null && admin_name != "" && admin_pwd != null && admin_pwd != "") {
            return adminMapper.selectAdmin(admin_name, admin_pwd);
        } else {
            return null;
        }
    }

    /**
     * 注册
     * @param adminName
     * @param adminPwd
     * @return
     */
    @Override
    public Boolean register(String adminName, String adminPwd) {
        if (adminName != null && adminName != "" && adminPwd != null && adminPwd != "") {
            Admin admin1 = new Admin();
            admin1.setAdminName(adminName);
            admin1.setAdminPwd(adminPwd);
            Admin admin = adminMapper.selectAdmin(adminName, "");
            if (admin == null) {
                int i = adminMapper.insertSelective(admin1);
                if (i == 1) {
                    return true;
                } else {
                    return false;
                }
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
}
